<template>
	<view class="flex-col page">
		<view class="note">
			<view class="title">使用须知</view>
			<view class="content">
				<view>1. 仅支持三天内的预约教室</view>
				<view>2. 生成密码<text style="color: #D85886;">有效期只有几分钟</text>，请在教室门口生成</view>
				<view>3. 如此时教室使用中，无法生成密码，<text style="color: #D85886;">请敲门</text>进入</view>
			</view>
		</view>
		<view class="order_title">
			三天内的预约
		</view>
		<view class="flex-col group" v-if="myReserveList.length">
			<view class="section_1" v-for="item in myReserveList" :key="item.id">
				<view class="flex-row" style="justify-content: space-between;">
					<view class="flex-row">
						<u-image width="144" height="144" :src="item.room_bannerimage" border-radius="8"></u-image>
						<view class="flex-col group_1">
							<text class="text_3">{{ item.store.store_name | substring(12) }}</text>
							<text class="text_4">{{ item.room.room_name | substring(8)}}</text>
							<text
								class="text_5">{{ item.starttime|setTime('YYYY/MM/DD HH:mm')}}-{{item.endtime|setTime('HH:mm')}}</text>
						</view>
					</view>
					<view class="unlock_button" @click="$u.throttle(open(item), 1000)">
						开锁
					</view>
				</view>
			</view>
		</view>
		<view class="flex-col group" v-else>
			<view class="flex-col group_empey">
				<view class="flex-col items-center group_2">
					<image src="../../static/svgicon/no_record.svg" class="img" />
				</view>
				<text class="text_1">近三天内无预约</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				myReserveList: [],
			}
		},
		onLoad() {
			this.$u.api.getMyRecentReserveList().then((res) => {
				this.myReserveList = res.data.reserves
			})
		},
		methods: {
			open({
				id,
				store: {
					store_latitude,
					store_longitude
				}
			}) {
				console.log(store_latitude);
				console.log(store_longitude);
				new Promise((resolve, reject) => {
					wx.getSetting({
						success: (res) => {
							resolve(res.authSetting['scope.userLocation']);
						},
						fail: (err) => {
							reject(err);
						}
					});
				}).then(
					(res) => {
						console.log(res);
						if (true == res) {
							uni.getLocation({
								type: 'gcj02',
								success: (res) => {
									let kk = this.distanceM(res.latitude, res.longitude, store_latitude,
										store_longitude)
									if (kk > 200) {
										uni.showModal({
											title: '提示',
											content: '你到教室距离还比较远，密码有效期5分钟，确定生成密码?',
											success: (res) => {
												// 请求生成密码
												if (res.confirm) {
													this.getpasswd(id)
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											},
											fail: function(err) {
												// 失败回调
												console.error(err);
											}
										});
									} else {
										this.getpasswd(id)
									}
								}
							});
						} else {
							this.getpasswd(id)
						}
					}
				)

			},

			getpasswd(id) {
				console.log('geting', id);
				this.$u.api.getOrderTmpPasswd({
					order_id: id
				}).then((res) => {
					if (0 == res.code) {
						uni.showModal({
							title: '提示',
							content: res.msg,
							showCancel: false,
						});
					}
					if (1 == res.code) {
						uni.showModal({
							title: '提示',
							content: `开门密码: ${res.data}`,
							showCancel: false,
						});
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.page {
		.note {
			padding: 24rpx;

			.title {
				font-weight: 500;
				font-size: 32rpx;
				color: #000000;
				text-align: center;
				padding: 24rpx 0 40rpx;
			}

			.content {
				white-space: pre-line;
				font-style: normal;
				font-weight: 400;
				font-size: 28rpx;
				line-height: 50rpx;
				color: #000000;
			}

		}

		.order_title {
			font-style: normal;
			font-weight: 500;
			font-size: 32rpx;
			line-height: 20px;
			color: #000000;
			margin-top: 40rpx;
			padding-left: 24rpx;
		}

		.unlock_button {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			background: linear-gradient(135deg, #E85389 15.23%, #E25588 84.77%);
			color: white;
			font-style: normal;
			font-weight: 500;
			font-size: 14px;
			line-height: 100rpx;
			text-align: center;
			margin-top: 26rpx;
			margin-right: 20rpx;
		}

		background-color: #ffffff;
		width: 100%;
		overflow-y: auto;
		height: 100%;

		.group_empey {
			color: rgb(51, 51, 51);
			font-size: 28rpx;
			font-weight: 200;
			line-height: 40rpx;
			white-space: nowrap;
			padding-top: 266rpx;

			.group_2 {
				position: relative;
				align-items: center;

				.img {
					width: 150rpx;
					height: 188rpx;
				}
			}

			.text_1 {
				margin-top: 54rpx;
				align-self: center;
			}
		}

		.button {
			margin-top: 52rpx;
			padding: 14rpx 0 16rpx;
			align-self: center;
			color: rgb(255, 255, 255);
			font-size: 36rpx;
			font-weight: 600;
			line-height: 50rpx;
			white-space: nowrap;
			background-color: rgb(216, 88, 134);
			border-radius: 8rpx;
			width: 300rpx;
		}

		.group {
			padding: 0rpx 22rpx 20rpx 24rpx;
			flex: 1 1 auto;
			overflow-y: auto;

			.button {
				border-radius: 8rpx;
				border: solid 4rpx rgb(216, 88, 134);
				color: #FFFFFF;
				background-color: rgb(216, 88, 134);
				font-size: 28rpx;
				font-weight: 600;
				line-height: 40rpx;
				align-items: center;
			}

			.hoverClass {
				background-color: rgba(216, 88, 134, 0.2);
				color: rgb(216, 88, 134);
				border: solid 4rpx rgb(216, 88, 134);
			}

			.section_1 {
				padding: 30rpx 22rpx;
				background-color: rgb(255, 255, 255);
				box-shadow: 0px 4rpx 8rpx 0px rgb(238, 235, 236);
				border-radius: 16rpx;
				border: solid 2rpx rgb(236, 236, 236);
				margin-top: 30rpx;

				.group_1 {
					margin-left: 32rpx;
					flex: 1 1 auto;

					.text_3 {
						color: rgb(51, 51, 51);
						font-size: 28rpx;
						font-weight: 600;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_4 {
						margin-top: 12rpx;
						color: rgb(51, 51, 51);
						font-size: 28rpx;
						font-weight: 200;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_5 {
						margin-top: 12rpx;
						color: rgb(51, 51, 51);
						font-size: 28rpx;
						font-weight: 200;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.group_2 {
						margin-top: 12rpx;
						color: rgb(51, 51, 51);
						font-size: 28rpx;
						font-weight: 600;
						line-height: 40rpx;
						white-space: nowrap;

						.text_7 {
							margin-left: 12rpx;
						}

						.image_3 {
							margin: 0rpx 0 0rpx 24rpx;
							width: 40rpx;
							height: 36rpx;
						}
					}

					.equal-division {
						margin-top: 32rpx;

						.equal-division-item {
							border: none;
							padding: 4rpx 15rpx 6rpx;
							flex: 1 1 208rpx;
							border-radius: 8rpx;
							border: solid 4rpx rgb(216, 88, 134);
							color: rgb(216, 88, 134);
							font-size: 28rpx;
							font-weight: 600;
							line-height: 40rpx;
							background-color: #FFFFFF;
							align-items: center;

							.text_8 {
								margin-left: 15rpx;
							}
						}

						.hoverClass {
							background-color: rgba(216, 88, 134, 0.2);
							color: rgb(216, 88, 134);
							border: solid 4rpx rgb(216, 88, 134);
						}
					}
				}
			}

			.left-section {
				height: 240rpx;
				overflow: hidden;
				// border: solid 4rpx rgb(216, 88, 134);
				border-radius: 16px;

				.text_1 {
					margin-top: 12rpx;

				}
			}

			.section_use {
				border: solid 4rpx rgb(236, 236, 236);
				color: rgba(213, 213, 213, 1);
			}

			.equal-division-item_1 {
				width: 208rpx;
				color: rgb(216, 88, 134);
				font-size: 28rpx;
				font-weight: 600;
				line-height: 40rpx;
				padding: 4rpx 14rpx 6rpx;
				border-radius: 8rpx;
				height: 62rpx;
				border: solid 4rpx rgb(216, 88, 134);
				background-color: #FFFFFF;
				align-items: center;

				.image_6 {
					width: 40rpx;
					height: 38rpx;
				}

				.text_9 {
					margin-left: 16rpx;
				}
			}

			.hoverClass {
				background-color: rgba(216, 88, 134, 0.2);
				color: rgb(216, 88, 134);
				border: solid 4rpx rgb(216, 88, 134);
			}

			.image_1 {
				width: 180rpx;
				height: 194rpx;
				border-radius: 16rpx;
			}

			.image_4 {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}
</style>